package com.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.entity.Bespeak;
import com.entity.Register;
import com.entity.Staff;
import com.service.BespeakService;
import com.service.RegisterService;
import com.service.StaffService;
import com.service.User1Service;

@Controller
public class controller {
	
	@Resource
	public User1Service user1Service;
	@Resource
	public StaffService staffService;
	@Resource
	public RegisterService registerService;
	@Resource
	public BespeakService bespeakService;
	
	public List<Staff> stafflist;
	public List<Register> registerlist;
	public List<Bespeak> bespeaklist;
 	
//	登录页面
	@RequestMapping("dl")
	public String dl(){
		
		return"dl";
	}
	
//	登录主页面
	@RequestMapping(value="top",method=RequestMethod.GET)
	public String top(int sid,Model model){
		stafflist = staffService.selectByPrimaryKey(sid);
		for (Staff s : stafflist) {
			System.out.println(s.getSname());
			model.addAttribute("name", s.getSname());
		}
		
		return"top";
	}
	@RequestMapping("left")
	public String left(){
		
		return"left";
	}
	@RequestMapping("page")
	public String page(){
		
		return"page";
	}
	
//	登录判断
	@RequestMapping(value="logein",method=RequestMethod.POST)
	public String logein(Staff staff,Model model){
//		账号的非空判断
		if (staff.getSuser().equals("")){
			
			model.addAttribute("ts2", "账号不能为空");
			return"dl";
		}
		
//		密码的非空判断
		if (staff.getSpwd().equals("")) {
			
			model.addAttribute("ts", "密码不可以为空");
			return"dl";
		}
		
		stafflist = staffService.setall();
		
		for (Staff s : stafflist) {
			
			if(staff.getSuser().equals(s.getSuser())&&staff.getSpwd().equals(s.getSpwd())){
			
				if(s.getSjob().equals("老板")){
					
					model.addAttribute("sid", s.getSid());
					return"logoin";
				}
				if(s.getSjob().equals("保安")){                                                                    
					return"logoin";
				}
				if(s.getSjob().equals("员工")){                                                                                                
					return"Monitor";
				}
			}else{
				model.addAttribute("ts", "账号或密码错误");
			}
		}
		return"dl";
	}
//	进入全屏模式
	@RequestMapping(value="whole",method=RequestMethod.GET)
	public String whole(Staff staff,Model model){
		
		
		registerlist = registerService.setall();
		bespeaklist = bespeakService.setall();
		model.addAttribute("bespeaklist", bespeaklist);
		model.addAttribute("registerlist", registerlist);
		return"whole";
	}
}
